function [w,b] = primalSVM(X,Y,C)

if (nargin < 2)
    error('Not enough arguments!');
end

[n,d] = size(X);
l = size(Y,1);
Xt = X(1:l,:);

if (nargin == 2)
    disp('Training hard-margin svm...');
    tic
    cvx_begin
    variable w(d,1);
    variable b;
    minimize (w'*w);
    Y.*(Xt*w+b) >= ones(l,1);
    cvx_end
    toc
else
    disp('Training soft-margin svm...');
    tic
    cvx_begin
    variable w(d,1);
    variable b;
    variable del(l,1) nonnegative;
    minimize (w'*w+2*C*sum(del));
    Y.*(Xt*w+b) >= ones(l,1) - del;
    cvx_end
    toc
    sum(del>0)
    sum(Y.*(Xt*w+b) == ones(l,1) - del)
end

end